package com.tsingteng.cosfun.ui.cosfun.presenter;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.ParagraphBean;
import com.tsingteng.cosfun.bean.PersonBean;
import com.tsingteng.cosfun.bean.VideoSignBean;
import com.tsingteng.cosfun.bean.WorkBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonCenterContract;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonEditContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.PersonCenterModel;
import com.tsingteng.cosfun.ui.cosfun.imodel.PersonEditModel;
import com.tsingteng.cosfun.utils.ToastUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PersonEditPresenter extends BasePresenter<PersonEditContract.IPersonEditView> implements PersonEditContract.IPersonInfo {

    PersonEditModel personEditModel = null;
    PersonEditContract.IPersonEditView iPersonEditView = null;

    public PersonEditPresenter(PersonEditContract.IPersonEditView iPersonCenterView) {
        this.personEditModel = new PersonEditModel();
        this.iPersonEditView = iPersonCenterView;
    }


    @Override
    public void editUserInfo(String image, String nickName, String birthday, int sex, String areaid, String signature) {
        Callback<BaseDataBean<PersonBean>> callback = new Callback<BaseDataBean<PersonBean>>() {


            @Override
            public void onResponse(Call<BaseDataBean<PersonBean>> call, Response<BaseDataBean<PersonBean>> response) {
                iPersonEditView.showEditResult(response.body());
            }

            @Override
            public void onFailure(Call<BaseDataBean<PersonBean>> call, Throwable t) {

            }
        };
        personEditModel.editUserInfo(image, nickName, birthday, sex, areaid, signature, callback);
    }

    @Override
    public void editUserInfo(String name, String value) {
        iPersonEditView.showLoading("");
        Callback<BaseDataBean> callback = new Callback<BaseDataBean>() {


            @Override
            public void onResponse(Call<BaseDataBean> call, Response<BaseDataBean> response) {
                iPersonEditView.hideLoading();
                iPersonEditView.showEditResult(response.body());
            }

            @Override
            public void onFailure(Call<BaseDataBean> call, Throwable t) {
                iPersonEditView.hideLoading();
            }
        };
        personEditModel.editUserInfo(name, value, callback);
    }

    @Override
    public void getPersonInfo(long profileId) {

        iPersonEditView.showLoading("");
        Callback<BaseDataBean<PersonBean>> callback = new Callback<BaseDataBean<PersonBean>>() {

            @Override
            public void onResponse(Call<BaseDataBean<PersonBean>> call, Response<BaseDataBean<PersonBean>> response) {
                iPersonEditView.hideLoading();
                iPersonEditView.showLogonResult(response.body());
            }

            @Override
            public void onFailure(Call<BaseDataBean<PersonBean>> call, Throwable t) {
                iPersonEditView.hideLoading();
            }
        };
        personEditModel.getPersonInfo(profileId, callback);

    }

    @Override
    public void getSignTureData(String typ) {
        Callback<BaseDataBean<VideoSignBean>> callback = new Callback<BaseDataBean<VideoSignBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<VideoSignBean>> call, Response<BaseDataBean<VideoSignBean>> response) {
                iPersonEditView.UploadVideo(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<VideoSignBean>> call, Throwable t) {
            }


        };
        personEditModel.getSignaTure(typ, callback);
    }

}
